home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE08 / DATADICT / MAINMENU.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-02-13  |  21.6 KB  |  732 lines

  1. unit Mainmenu;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Menus, inifiles, buttons, dbtables, DB,
  8.   filectrl,
  9.   utils,     {misc support}
  10.   dbutils,   {openDB, etc.}
  11.   importDD,  {AddToDict}
  12.   about,
  13.   ddedDlg,   {edit data dictionary}
  14.   gentable,  {generate tables from data dictionary}
  15.   createdd,  {Make a new dictionary}
  16.   BrowseDD,  {Browse the data dictionary}
  17.   {dbctrl,    {set up tfields}
  18.   {scaler,     {user controled scale form utility}
  19.   runinfo, ExtCtrls, Grids;   {Heap & DB info display}
  20.  
  21. type
  22.   DDValidationtype = (IsValidDD, DoesNotExist, ExistbutnotDD, NewDD, EmptyString );
  23.   TMain = class(TForm)
  24.     DictTable: TTable;
  25.     DictDataSource: TDataSource;
  26.     DictQuery: TQuery;
  27.     SourceDatabase: TDatabase;
  28.     MainMenu1: TMainMenu;
  29.     File1: TMenuItem;
  30.     Edit1: TMenuItem;
  31.     Edit2: TMenuItem;
  32.     Browse1: TMenuItem;
  33.     About1: TMenuItem;
  34.     Options: TMenuItem;
  35.     NewDD1: TMenuItem;
  36.     OpenDD1: TMenuItem;
  37.     N1: TMenuItem;
  38.     Exit1: TMenuItem;
  39.     Label1: TLabel;
  40.     M_status: TMemo;
  41.     DDEditbox: TEdit;
  42.     B_DDlist: TBitBtn;
  43.     DDListBox: TListBox;
  44.     FontDialog1: TFontDialog;
  45.     AboutDDict1: TMenuItem;
  46.     RunInfo1: TMenuItem;
  47.     OpenDialog: TOpenDialog;
  48.     DefineexistingDB1: TMenuItem;
  49.     Help1: TMenuItem;
  50.     Printdictionary1: TMenuItem;
  51.     N2: TMenuItem;
  52.     Generateunittocreatedatabase1: TMenuItem;
  53.     Createemptydatabase1: TMenuItem;
  54.     N3: TMenuItem;
  55.     N4: TMenuItem;
  56.     Designatetargetdirectory1: TMenuItem;
  57.     Label5: TLabel;
  58.     Labele: TLabel;
  59.     Label8: TLabel;
  60.     L_update: TLabel;
  61.     L_size: TLabel;
  62.     L_numrecs: TLabel;
  63.     Label4: TLabel;
  64.     L_numTables: TLabel;
  65.     L_curTable: TLabel;
  66.     targetDatabase: TDatabase;
  67.     TargetTable: TTable;
  68.     TargetDataSource: TDataSource;
  69.     TargetQuery: TQuery;
  70.     LB_allFields: TListBox;
  71.     L_allfields: TLabel;
  72.     LB_curFields: TListBox;
  73.     LB_tables: TListBox;
  74.     SG_Summary: TStringGrid;
  75.     procedure FormCreate(Sender: TObject);
  76.     function  CheckOutDD(Sender: Tobject; whichone : integer) : DDValidationType;
  77.     procedure SetUpAlias(sender: Tobject; whichone : integer);
  78.     procedure Edit2Click(Sender: TObject);
  79.     procedure NewDD1Click(Sender: TObject);
  80.     function  MakeNewDD(sender: TObject; const filespec : string) : boolean;
  81.     procedure SelectDD(Sender: TObject);
  82.     procedure B_DDlistClick(Sender: TObject);
  83.     procedure DDListBoxClick(Sender: TObject);
  84.     procedure DDEditboxKeyDown(Sender: TObject; var Key: Word;
  85.       Shift: TShiftState);
  86.     procedure DDListBoxExit(Sender: TObject);
  87.     procedure FormDestroy(Sender: TObject);
  88.     procedure DDEditboxDblClick(Sender: TObject);
  89.     procedure FontchangeClick(Sender: TObject);
  90.     procedure RunInfo1Click(Sender: TObject);
  91.     procedure OpenDD1Click(Sender: TObject);
  92.     procedure Exit1Click(Sender: TObject);
  93.     procedure Browse1Click(Sender: TObject);
  94.     procedure AboutDDict1Click(Sender: TObject);
  95.     {procedure Resize1Click(Sender: TObject);}
  96.     procedure Button1Click(Sender: TObject);
  97.     procedure DefineexistingDB1Click(Sender: TObject);
  98.     procedure Designatetargetdirectory1Click(Sender: TObject);
  99.     procedure Createemptydatabase1Click(Sender: TObject);
  100.     procedure LB_tablesClick(Sender: TObject);
  101.     procedure LB_curFieldsClick(Sender: TObject);
  102.     procedure LB_allFieldsClick(Sender: TObject);
  103.     procedure FormActivate(Sender: TObject);
  104.     procedure Printdictionary1Click(Sender: TObject);
  105.     procedure Generateunittocreatedatabase1Click(Sender: TObject);
  106.     procedure Help1Click(Sender: TObject);
  107.   private
  108.     FValidDD : DDValidationType;  {flag on status of current contents of DDeditbox}
  109.     FIniFile : TIniFile;
  110.     procedure initDDeditStuff;  {initialize with no ini file}
  111.     procedure NotImplemented(const what: string);
  112.   public
  113. {    DataDictCtrl : tDDCtrl;}
  114.     FCtrlDictName : string;   {name of data dictionary that controls DB in this app}
  115.     NewDDName,
  116.     DDPathName,
  117.     DDTableName,
  118.     TargetPathName  : string;
  119.     EditThisField : boolean;
  120.     GoToTable,
  121.     GoToField : string;
  122.     DictWasChanged : boolean;
  123.     Procedure ReadIniFile;
  124.     Procedure ChangeIniFile;
  125.   end;
  126.  
  127. var
  128.   Main: TMain;
  129.  
  130. implementation
  131. uses
  132. mystrng
  133. {$ifdef buggy}
  134. , toolhelp;
  135. {$else}
  136. ;
  137. {$endif}
  138.  
  139.  
  140. {$R *.DFM}
  141.  
  142. {========================= Main form routines ===========================}
  143.  
  144. procedure Tmain.initDDeditStuff;
  145. begin
  146.   l_size.caption := '';
  147.   l_update.caption := '';
  148.   l_numtables.caption := '';
  149.   {l_numfields.caption := '';}
  150.   l_numrecs.caption := '';
  151.   ddEditBox.text := 'No Dictionary active.';
  152.   lb_tables.items.clear;
  153.   FCtrlDictName := '';
  154.   DictWasChanged := false;
  155. end;
  156.  
  157.  
  158. procedure TMain.FormCreate(Sender: TObject);
  159. begin
  160. {  M_checkout.lines.clear;}
  161.   SourceDatabase.close;
  162.   SourceDatabase.Params.Clear;
  163.  {$IFDEF buggy}
  164.   tstlst := tstringlist.create;
  165.  {$ENDIF}
  166.   scaleform(self);
  167.   ReadIniFile;
  168.   If DDeditBox.text = ''
  169.     then initDDeditStuff
  170.     else setUpAlias(sender, 0);
  171. {  DataDictCtrl := tDDctrl.create(self);}
  172. end;
  173.  
  174. procedure TMain.FormDestroy(Sender: TObject);
  175. begin
  176.  ChangeIniFile;
  177. {$IFDEF buggy}
  178.  tstlst.free;
  179. {$ENDIF}
  180. end;
  181.  
  182. Procedure TMain.ReadIniFile;
  183. var tmpstr : string;
  184. begin
  185.   FIniFile := TiniFile.Create(appname+'.ini');
  186.   FiniFile.ReadSection('DDFiles', DDListBox.items);
  187.   if DDListBox.items.count = 0
  188.       then DDEditBox.text := ''
  189.       else DDEditBox.text := DDListBox.items[0];
  190.   FCtrlDictName := FiniFile.ReadString('CtrlDict', 'current', appname+'.dbf');
  191.   FiniFile.free;
  192. end;
  193.  
  194. Procedure TMain.ChangeIniFile;
  195. var i : integer;
  196. begin
  197.   FIniFile := TiniFile.Create(appname+'.ini');
  198.   FiniFile.eraseSection('DDFiles');
  199.   for i := 0 to DDListBox.items.count -1 do
  200.     FiniFile.writeString('DDFiles', DDListBox.items[i], '1');
  201.   FiniFile.free;
  202. end;
  203.  
  204. {======================= Data Dictionary selection routines ===============}
  205.  
  206. function Tmain.CheckOutDD(sender: tObject; whichone : integer): DDValidationtype;
  207. var
  208.     tablefound : boolean;
  209.     sqlstr,
  210.     thistable : string;
  211.     pathname : dirstr;
  212.     tablenum,
  213.     numtables,
  214.     numFields : integer;
  215.     FileInfo : TsearchRec;
  216.     tableField : tField;
  217.  
  218.     function FieldInfo: string;
  219.     begin
  220.     end;
  221.  
  222. begin
  223.   result := isValidDD;
  224.   numtables := 0;  numFields := 0;
  225.   l_size.caption := '';
  226.   l_update.caption := '';
  227.   l_numtables.caption := '';
  228.   {l_numfields.caption := '';}
  229.   l_numrecs.caption := '';
  230.   lb_tables.items.clear;
  231.   lb_curFields.items.clear;
  232.   lb_allFields.items.clear;
  233.   if fileExists(DDListBox.items[whichone])
  234.     then begin
  235.       FindFirst(DDListBox.items[whichone], faAnyfile, fileinfo);
  236.       L_update.caption := datetimetostr(fileDateToDateTime(Fileinfo.time));
  237.       l_size.caption := IntTostr(FileInfo.size);
  238.       {not total size, should also get size of .dbt }
  239.       end
  240.     else begin
  241.       cursor := crDefault;
  242.       result := DoesNotExist;
  243.       m_status.hide;
  244.       exit;
  245.       end;
  246.  DictCtrl.OpenDictionary(DDEditBox.text, SourceDataBase, DictTAble, DictQuery, DictDataSource);
  247.  SG_summary.rowcount := DictCtrl.FDBSG.rowcount +1 ; {extra row for field names}
  248.  SG_summary.colcount := DictCtrl.FDBSG.colcount;
  249.  for numFields := ord(ddfTable_name) to ord(ddfformula) do
  250.    SG_summary.cells[numFields,0] := DictTableFieldNames[ddfOffsets(NumFields)];
  251.  for numfields := ord(ddfTable_name) to ord(ddfformula) do
  252.    SG_summary.rows[numfields+1] := DictCtrl.FDBSG.rows[numfields];
  253.  
  254. {This section could be eliminated since the section above grabs all the
  255. relevant information; but if eliminated, l_numrecs, etc need to be
  256. set from this info}
  257.   if openDB(SourceDataBase, DictTAble, DictQuery, DictDataSource,
  258.             DDPathName, DDTableName)
  259.     then begin
  260.       l_numrecs.caption := intToStr(dictTable.RecordCount);
  261.       sqlstr := 'SELECT * FROM '+DDTableName;
  262.       Dictquery.sql.add(sqlstr);
  263.       Dictquery.prepare;
  264.       Dictquery.open;
  265.       Dictquery.first;
  266.       { get tablenames in data dictionary, stick in M_tableList lines}
  267.       if DictQuery.findfield('TABLE_NAME') = nil
  268.         then begin
  269.            cursor := crDefault;
  270.            MessageDlg(DDListBox.items[whichone]+#13+'is not a Data Dictionary Database.', mtInformation, [mbOK], 0);
  271.            m_status.hide;
  272.            result := ExistButNotDD;
  273.            exit;
  274.            end;
  275.       lb_tables.items.add(DictQuery.findfield('TABLE_NAME').text);  {get first one}
  276.       lb_allfields.items.add(fieldSummary(DictQuery));
  277.       inc(numfields);
  278.       DictQuery.next;
  279.       while not DictQuery.eof do begin
  280.         tablefound := false;
  281.         thistable := DictQuery.findfield('TABLE_NAME').text;
  282.         lb_allfields.items.add(fieldSummary(DictQuery));
  283.         inc(numFields);
  284.         for tablenum := 0 to lb_tables.items.count - 1 do
  285.           if lb_tables.items[tablenum] = thistable
  286.              then begin
  287.                 tablefound := true;
  288.                 break;
  289.                 end;
  290.           {done looking for thistable}
  291.         if not tablefound
  292.           then  lb_tables.items.add(thistable);
  293.         DictQuery.next;
  294.         end; {while searching for table names}
  295.     l_numtables.caption := intToSTr(lb_tables.items.count);
  296.     {l_numfields.caption := IntToStr(numfields);}
  297.     l_allfields.caption := 'All '+IntToStr(numfields)+' fields';
  298. {    thistable := MinimizeName(DDEditBox.text, Canvas,
  299.                            GroupBox1.width-canvas.TextWidth('Dictionary: '));
  300.     groupbox2.caption := 'Dictionary: '+thistable;
  301.  }
  302.     DictQuery.close;
  303.     Sourcedatabase.close;
  304.  
  305.     end
  306.   else begin
  307.     l_size.caption := '';
  308.     l_update.caption := '';
  309.     m_status.hide;
  310.     result := ExistbutnotDD;
  311.     end;
  312. end;
  313.  
  314.  
  315. (**
  316.   try
  317.     SourceDataBase.close;
  318.     SourceDatabase.Params.clear;
  319.     SourceDatabase.Params.Add('PATH='+DDPathName);
  320.     SourceDatabase.open;
  321.     DictTable.DatabaseName:= SourceDataBase.databasename;
  322.     DictTable.tablename := DDTableName;
  323.     DictTable.Active:= True;
  324.     l_numrecs.caption := intToStr(dictTable.RecordCount);
  325.     DictDataSource.DataSet:= DictTable;
  326.     DictQuery.databaseName := SourceDataBase.databasename;
  327.     Dictquery.dataSource := DictDataSource;
  328.     Dictquery.close;
  329.     Dictquery.sql.clear;
  330.     Dictquery.params.clear;
  331.     sqlstr := 'SELECT * FROM '+DDTableName;
  332.     Dictquery.sql.add(sqlstr);
  333.     Dictquery.prepare;
  334.     Dictquery.open;
  335.     Dictquery.first;
  336.     { get tablenames in data dictionary, stick in M_tableList lines}
  337.     if DictQuery.findfield('TABLE_NAME') = nil
  338.       then begin
  339.          cursor := crDefault;
  340.          MessageDlg(DDListBox.items[whichone]+#13+'is not a Data Dictionary Database.', mtInformation, [mbOK], 0);
  341.          m_status.hide;
  342.          result := ExistButNotDD;
  343.          exit;
  344.          end;
  345.     lb_tables.items.add(DictQuery.findfield('TABLE_NAME').text);  {get first one}
  346.     inc(numfields);
  347.     DictQuery.next;
  348.     while not DictQuery.eof do begin
  349.       tablefound := false;
  350.       thistable := DictQuery.findfield('TABLE_NAME').text;
  351.       inc(numFields);
  352.       for tablenum := 0 to lb_tables.items.count - 1 do
  353.         if lb_tables.items[tablenum] = thistable
  354.            then begin
  355.               tablefound := true;
  356.               break;
  357.               end;
  358.         {done looking for thistable}
  359.       if not tablefound
  360.         then  lb_tables.items.add(thistable);
  361.       DictQuery.next;
  362.       end; {while searching for table names}
  363.   except
  364.      on EdataBaseError do begin
  365.        cursor := crDefault;
  366.        MessageDlg('Not a data base file or other DB error', mtInformation, [mbOK], 0);
  367.        l_size.caption := '';
  368.        l_update.caption := '';
  369.        m_status.hide;
  370.        result := ExistbutnotDD;
  371.        end;
  372.      end; {of exceptions}
  373.   l_numtables.caption := intToSTr(lb_tables.items.count);
  374.   l_numfields.caption := IntToStr(numfields);
  375.   thistable := MinimizeName(DDEditBox.text, Canvas,
  376.                          GroupBox1.width-canvas.TextWidth('Dictionary: '));
  377.   groupbox2.caption := 'Dictionary: '+thistable;
  378.   DictQuery.close;
  379.   Sourcedatabase.close;
  380. end;
  381. **)
  382.  
  383. Procedure Tmain.SetUpAlias(sender : tObject; whichone : integer);
  384. begin
  385.     DDPathName := extractFilePath(DDListBox.items[whichone]);
  386.     DDTableName := extractFileName(DDListBox.items[whichone]);
  387.     DDTableName := copy(DDTableName, 1, pos('.', DDtableName)-1);
  388.     m_status.lines.clear;
  389.     m_status.show;
  390.     m_status.lines.add('Checking out Dictionary:');
  391.     m_status.lines.add('Path:  '+DDPathName);
  392.     m_status.lines.add('Table:  '+DDTableName);
  393.     m_status.update;
  394.     cursor := crHourglass;
  395.     FValidDD := CheckoutDD(sender, whichone);
  396.     m_status.hide;
  397.     cursor := crDefault;
  398.     case FValidDD of
  399.       IsValidDD : begin
  400.                     if whichone <> 0
  401.                       then DDListBox.items.exchange(0, whichone);
  402.                   end;
  403.       DoesNotExist : begin
  404.                       l_size.caption := '';
  405.                       l_update.caption := '';
  406.                       if messagedlg(DDListBox.items[whichone]+#13+
  407.                                   'This data dictionary does not exist.'+#13+
  408.                                   ' Click OK to create new, empty DD.',
  409.                                    mtConfirmation, [mbOK,mbCancel], 0) = mrOk
  410.                         then
  411.                            if not makenewDD(sender, DDListBox.items[whichone])
  412.                               then DDListBox.items.delete(whichone);
  413.                       end;
  414.       ExistButNotDD : begin
  415.                        DDListBox.items.delete(whichone);
  416.                        DDEditBox.text := '';
  417.                       end;
  418.       end;
  419.     DDListBox.hide;
  420.     DictWasChanged := false;
  421. end;
  422.  
  423.  
  424. procedure TMain.Edit2Click(Sender: TObject);
  425. begin
  426.   if FvalidDD = IsValidDD
  427.     then DDmultpagedlg.show;
  428.   if DictWasChanged
  429.     then selectDD(sender);
  430. end;
  431.  
  432. procedure TMain.NewDD1Click(Sender: TObject);
  433.  begin
  434.    with openDialog do begin
  435.      Options := [ofPathMustExist] - [ofFileMustExist];
  436.      title := 'Enter name of new dictionary';
  437.      end;
  438.   if OpenDialog.Execute
  439.     then begin
  440.       If fileExists(OpenDialog.FileName)
  441.         then begin
  442.           MessageDlg('File exists already', mtInformation, [mbOK], 0);
  443.           exit;
  444.           end
  445.         else begin
  446.           NewDDname := opendialog.filename;
  447.           createDDForm.showmodal;
  448.           if CreateDDForm.modalResult = mrYes
  449.             then begin
  450.               DDEditBox.text := newDDName;
  451.               selectDD(sender);
  452.               end
  453.             else messagedlg('unsuccessful attempt to build new dd',
  454.                          mtinformation, [mbOK], 0);
  455.           end;
  456.       end;
  457. end;
  458.  
  459. function Tmain.makenewDD(sender: Tobject; const filespec : string): boolean;
  460. begin
  461.   If fileExists(filespec)
  462.     then begin
  463.        {not needed, this only called when file not found... I hope}
  464.       MessageDlg(Filespec +' exists already', mtInformation, [mbOK], 0);
  465.       result := false;
  466.       end
  467.     else begin
  468.       NewDDname := filespec;
  469.       createDDForm.showmodal;
  470.       if CreateDDForm.modalResult = mrYes
  471.         then begin
  472.           result := true;
  473.           DDEditBox.text := newDDName;
  474.           selectDD(sender);
  475.           end
  476.         else begin
  477.           messagedlg('unsuccessful attempt to build new dd',
  478.                      mtinformation, [mbOK], 0);
  479.           result := false;
  480.           end;
  481.       end;
  482. end;
  483.  
  484. procedure TMain.SelectDD(Sender: TObject);
  485.   var i : integer;
  486.     found : boolean;
  487. begin
  488.   with DDListBox do
  489.     begin
  490.       found := false;
  491.       for i := 0 to items.count -1 do
  492.         if DDEditBox.text = items[i]
  493.           then begin
  494.             found := true;
  495.             break;
  496.             end;
  497.       if found
  498.         then setUpAlias(sender, i)
  499.         else begin
  500.           items.add(DDEditBox.text);
  501.           setUpAlias(sender, items.count -1);
  502.           end;
  503.       end;
  504. end;
  505.  
  506.  
  507. procedure TMain.B_DDlistClick(Sender: TObject);
  508. begin
  509.   DDListBox.show;
  510. end;
  511.  
  512. procedure TMain.DDListBoxClick(Sender: TObject);
  513. begin
  514.   DDEditBox.text := DDListBox.items[DDListBox.itemindex];
  515.   DDListBox.hide;
  516.   SelectDD(sender);
  517. end;
  518.  
  519. procedure TMain.DDEditboxKeyDown(Sender: TObject; var Key: Word;
  520.   Shift: TShiftState);
  521. begin
  522.   if key = VK_RETURN
  523.     then SelectDD(Sender);
  524. end;
  525.  
  526. procedure TMain.DDListBoxExit(Sender: TObject);
  527. begin
  528.   DDListBox.hide;
  529. end;
  530.  
  531. procedure TMain.DDEditboxDblClick(Sender: TObject);
  532. begin
  533.   if FValidDD = IsValidDD
  534.     then DDmultpagedlg.show
  535.     else selectDD(sender);
  536. end;
  537.  
  538. procedure TMain.OpenDD1Click(Sender: TObject);
  539. begin
  540.   with openDialog do begin
  541.     filename := '*.dbf';
  542.     options := [ofPathMustExist, ofFileMustExist] ;
  543.     title := 'Select existing dictionary dbf';
  544.     end;
  545.   if OpenDialog.Execute
  546.     then begin
  547.           DDEditBox.text := OpenDialog.FileName;
  548.           SelectDD(sender);
  549.           end;
  550. end;
  551.  
  552.  
  553.  
  554.  
  555. {=================== misc ============================}
  556.  
  557.  
  558. procedure TMain.FontchangeClick(Sender: TObject);
  559. begin
  560.   FontDialog1.Font := Main.Font;
  561.   if FontDialog1.Execute then
  562. Main.Font := FontDialog1.Font;
  563. end;
  564.  
  565. procedure TMain.RunInfo1Click(Sender: TObject);
  566. begin
  567.   runinfoform.updateinfo('Main About click');
  568.   runinfoform.show;
  569. end;
  570.  
  571.  
  572. procedure TMain.Exit1Click(Sender: TObject);
  573. begin
  574. {$IFDEF buggy}
  575.  runinfoform.updateinfo('Main Close');
  576.  runinfoform.show;
  577. {$ENDIF}
  578.   close;
  579. end;
  580.  
  581. procedure TMain.Browse1Click(Sender: TObject);
  582. begin
  583.   BrowseDDForm.FormActivate(sender);
  584. end;
  585.  
  586. procedure TMain.AboutDDict1Click(Sender: TObject);
  587. begin
  588.   AboutBox.show;
  589. end;
  590.  
  591. {procedure TMain.Resize1Click(Sender: TObject);
  592. begin
  593.   ScalerForm.setWhichForm(main);
  594.   if ScalerForm.showmodal = mrYes
  595.     then update;
  596. end;}
  597.  
  598.  
  599. procedure TMain.Button1Click(Sender: TObject);
  600. begin
  601.   {DataDictCtrl := tDDctrl.create(self);}
  602. {    SourceDataBase.close;
  603.     SourceDatabase.Params.clear;
  604.     SourceDatabase.Params.Add('PATH='+DDPathName);
  605.     SourceDatabase.open;
  606.     DictTable.DatabaseName:= SourceDataBase.databasename;
  607.     DictTable.tablename := DDTableName;
  608.     DictTable.Active:= True;
  609.     DictDataSource.DataSet:= DictTable;
  610.     DictQuery.databaseName := SourceDataBase.databasename;
  611.     Dictquery.dataSource := DictDataSource;
  612.     Dictquery.close;
  613.   dictCtrlForm.show;
  614.   if dictCtrlForm.FillTableDef(DictQuery, DDTableName) = success
  615.     then begin
  616.       setFieldDef(DictTable, 'Element', 'Table_Name');
  617.       end;}
  618. end;
  619.  
  620. procedure TMain.DefineexistingDB1Click(Sender: TObject);
  621. var thisfile : integer;
  622. begin
  623.   if not (FValidDD = IsValidDD)
  624.     then begin
  625.       messageDlg('Open a dictionary first', mtInformation, [mbOK], 0);
  626.       exit;
  627.       end;
  628.   with opendialog do begin
  629.     options := [ofPathMustExist, ofFileMustExist, ofAllowMultiSelect];
  630.     title := 'Select table(s) to pull into data dictionary';
  631.     end;
  632.   if OpenDialog.Execute
  633.     then begin
  634.       if l_numrecs.caption <> ''
  635.         then
  636.           if MessageDlg('Append to existing records?', mtConfirmation, [mbYes,mbNo], 0) = mrNo
  637.             then exit;
  638.       for thisfile := 0 to OpenDialog.files.count -1 do
  639.         begin
  640.           AddToDict(SourceDatabase, DictTable, DictQuery, DictDataSource,
  641.                     TargetDatabase, TargetTable, TargetQuery, TargetDataSource,
  642.                     DDPathName, DDTableName,
  643.                     ExtractFilePath(OpenDialog.files[thisfile]),
  644.                     ExtractFileName(OpenDialog.files[thisfile]));
  645.           SelectDD(sender);
  646.         end;
  647.     end;
  648. end;
  649.  
  650.  
  651. procedure TMain.Designatetargetdirectory1Click(Sender: TObject);
  652. begin
  653.   BuildTableForm.show;
  654. end;
  655.  
  656. procedure TMain.Createemptydatabase1Click(Sender: TObject);
  657. begin
  658.   if checkoutDD(sender, 0) = IsValidDD
  659.     then BuildTableForm.show
  660.     else messageDlg('no valid dictionary...', mtError, [mbOK],0);
  661. end;
  662.  
  663. procedure TMain.LB_tablesClick(Sender: TObject);
  664. var i, count : integer;
  665.   thistable : string;
  666. begin
  667.   LB_curFields.items.clear;
  668.   thisTable := LB_Tables.items[LB_tables.itemindex];
  669.   count := 0;
  670.   for i := 0 to LB_AllFields.items.count - 1 do
  671.     if get_word(LB_allFields.items[i], 1) = thisTable
  672.       then begin
  673.         LB_curFields.items.add(copy(LB_allFields.items[i], length(thistable)+3,255));
  674.         inc(count);
  675.         end;
  676.   L_curTable.caption := intTostr(count)+' fields in '+thistable;
  677. end;
  678.  
  679. procedure TMain.LB_curFieldsClick(Sender: TObject);
  680. begin
  681.   if FvalidDD = IsValidDD
  682.     then begin
  683.       EditThisField := true;
  684.       goToTable := trim(LB_Tables.items[LB_tables.itemindex]);
  685.       GoToField := trim(get_word(LB_curFields.items[LB_curFields.itemindex],1));
  686.       DDmultpagedlg.show;
  687.       end;
  688.   if DictwasChanged
  689.     then selectDD(sender);
  690.   EditThisField := false;
  691. end;
  692.  
  693. procedure TMain.LB_allFieldsClick(Sender: TObject);
  694. begin
  695.   if FvalidDD = IsValidDD
  696.     then begin
  697.       EditThisField := true;
  698.       goToTable := get_word(LB_allFields.items[LB_allFields.itemindex], 1);
  699.       GoToField := get_word(LB_allFields.items[LB_allFields.itemindex],3);
  700.       DDmultpagedlg.show;
  701.       end;
  702.   EditThisField := false;
  703. end;
  704.  
  705. procedure TMain.FormActivate(Sender: TObject);
  706. begin
  707.   if DictwasChanged
  708.     then selectDD(sender);
  709. end;
  710.  
  711. procedure TMain.Printdictionary1Click(Sender: TObject);
  712. begin
  713.   NotImplemented('Print Dictionary');
  714. end;
  715.  
  716. procedure TMain.Generateunittocreatedatabase1Click(Sender: TObject);
  717. begin
  718.   NotImplemented('Make Pascal unit to Generate table(s)');
  719. end;
  720.  
  721. procedure TMain.Help1Click(Sender: TObject);
  722. begin
  723.   NotImplemented('Help system');
  724. end;
  725.  
  726. procedure TMain.NotImplemented(const what: string);
  727. begin
  728.   MessageDlg(What+#13+'is not implemented yet...', mtInformation, [mbOK],0);
  729. end;
  730.  
  731. end.
  732.